package com.ht.mt.sric.sesion;

import com.ht.mt.sric.entity.Tramo;
import com.ht.mt.sric.sesion.local.TramoSessionEJBBeanLocal;
import com.ht.mt.sric.sesion.remota.TramoSessionEJBBeanRemote;

import java.util.List;

import javax.annotation.Resource;

import javax.ejb.SessionContext;
import javax.ejb.Stateless;

import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless(name = "TramoSessionEJBBean", mappedName = "TramoSessionEJBBean")
public class TramoSessionEJBBean implements TramoSessionEJBBeanRemote, TramoSessionEJBBeanLocal {
    @Resource
    SessionContext sessionContext;
    @PersistenceContext(unitName = "sric_ejb")
    private EntityManager em;

    public TramoSessionEJBBean() {
    }

    public Tramo persistTramo(Tramo tramo) {
        em.persist(tramo);
        return tramo;
    }

    public Tramo mergeTramo(Tramo tramo) {
        return em.merge(tramo);
    }

    public void removeTramo(Tramo tramo) {
        tramo = em.find(Tramo.class, tramo.getIdTrm());
        em.remove(tramo);
    }

    /** <code>select o from Tramo o</code> */
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public List<Tramo> getTramoFindAll() {
        return em.createNamedQuery("Tramo.findAll", Tramo.class).getResultList();
    }
}
